{extend name="public/base"/}
{block name="css"}
<style>
.fa-check{color:#00a65a}
.fa-close{color:#dd4b39}
</style>
{/block}
 {block name="content"}
       <!-- Content Header (Page header) -->
<section class="content-header">
<h1>
           内容管理
<small>Optional description</small>
</h1>
<ol class="breadcrumb">
	<li><a href="{:U('Index/index')}"><i class="fa fa-dashboard"></i> 首页</a></li>
	<li class="active">内容管理</li>
</ol>
</section>
<!-- Main content -->
<section class="content" style="min-height:980px;">
<div class="col-md-9" style="padding:0; width:100%">
	<div class="box box-primary">
		<div class="box-header with-border">
			<h3 class="box-title" style="float:left;overflow: hidden;zoom:1;padding-top: 8px;"><a href="{:U('Content/addSliderContent')}" class="btn btn-primary">内容发布</a></h3>
			<div class="box-tools pull-right" style="margin-right: 200px;margin-top: -10px">
				<dl>
					<dd class="ftype_select-linkage" id="nodeterm">
							<select class="form-control parent_one"  style="float:left;margin-right:10px;width: 200px">
								<option value="0">所有栏目</option>
								{volist name="parentterm" id="data"}
								<option value="{$data.id}" dataterm="{$data.parent_id}" data-model="{$data.model_id}">{$data.name}</option>
								{/volist}
							</select>
					</dd>
				</dl>
			</div>
			<script>
				$(document).ready(function() {

					$("body").on('change', '.parent_one', function() {
						var term_id = $(this).val();
						var thisitem = $(this);
						var parentid = $(this).find("option:selected").attr('dataterm');

						if(parentid==0){
							thisitem.nextAll().remove();
						}
						if(term_id==0){
							window.location.reload();
							thisitem.nextAll().remove();
						}else{
							$.post('{:U("Content/gettermchild")}', {
								term_id: term_id
							}, function(data, textStatus, xhr) {
								if(data == 2){
									thisitem.next().remove()
								}else{
									$("#nodeterm").append(data);
								}

							});
						}

						$.post('{:U("Content/getlistpage")}', {
							term_id: term_id
						}, function(data, textStatus, xhr) {
							$("#pagedata").html(data);
						});
					});

				});
			</script>
			<!-- 搜索 -->
			<form action="{:U('Content/listindex')}" method="get">

			<div class="box-tools pull-right">

                <div class="has-feedback" style="zoom:1;overflow: hidden;">
                    {if (strpos(C('base_url'), '?'))}
                    <input name="s" type="hidden" value="{:substr(U('Content/listindex'), strlen(C('base_url')))}"> 
                    {/if}
                    <input type="text" class="form-control input-sm" name="name" value="" placeholder="输入标题名称" style="float:left;">

					<input  style="border:0;float: left; font-size: 12px; height: 30px; position: absolute; right: 0; top: 0;" type="submit" value="搜索" />

				</div>
			</div>
			</form>
			<!-- 搜索 END-->
		</div>
			{include file="content/getlistpage" /}
	</div>
	<!-- /. box -->
</div>

<!-- 批量删除 -->
<script>
$(function () {

	$("#all").click(function(){
    	if(this.checked){
        	$("#list :checkbox").prop("checked", true);
    	}else{
			$("#list :checkbox").prop("checked", false);
    	}
 	});

    $("#selectAll").click(function () {
         $("#list :checkbox,#all").prop("checked", true);
    });

    $("#unSelect").click(function () {
         $("#list :checkbox,#all").prop("checked", false);
    });

    $("#reverse").click(function () {
         $("#list :checkbox").each(function () {
              $(this).prop("checked", !$(this).prop("checked"));
         });
		 allchk();
    });

	$("#list :checkbox").click(function(){
		allchk();
	});

    $(".alter").click(function(){
        var id = $(this).parent().parent().attr('data-id');
        var field = $(this).attr('field');
        var obj = $(this);
        $.ajax({
            type:"get",
            url:"{:U('Content/alterState')}",
            dataType: "json",
            data:{field:field, id:id},
            success: function(json){
                if(!json.err){
                    obj.attr('state', json.state);
                    obj.html(getStateStr(json.state));
                }else{
                    obj.html(getStateStr(obj.attr('state')));
                }
            },
            error: function(){
                obj.html(getStateStr(obj.attr('state')));
            },
        });
    });
});

    function getStateStr(state){
        state = (state==1)?'check':'close';
        var str = '&nbsp<span class="fa fa-'+state+'"></span>';
        return str;
    }

	function getValue(){
        var id = document.getElementsByName('select_id');
        var value = new Array();
        for(var i = 0; i < id.length; i++){
            if(id[i].checked)
                value.push(id[i].value);
        }
        return value;
    };

    function batchDelete(){
        var value = getValue();
        if(!confirm("确定删除这"+value.length+"项吗？"))
            return false;
        $.ajax({
            type:"post",
            url:"{:U('Content/batchDelete')}",
            dataType: "json",
            data:{ idList:value, },
            success: function(json){
                if(!json.err)
                    history.go(0);
                else
                    alert(json.msg);
            },
            error: function(){
                alert('删除失败');
            },
        });
    }


	function allchk(){
		var chknum = $("#list :checkbox").size();
		var chk = 0;
		$("#list :checkbox").each(function () {
			if($(this).prop("checked")==true){
				chk++;
			}
		});
		if(chknum==chk){
			$("#all").prop("checked",true);
		}else{
			$("#all").prop("checked",false);
		}
	}


	<!-- 排序开始-->
	$(":text").change(function(){
			$.ajax({
			  type:"post",
			  url:"{:U('Content/listorder')}",
			  dataType: "json",
			  data:{
				  listorder:$(this).val(),
				  listorder_id:$(this).data("orderid"),
			  },
			  success:　
			  function(data){
			   alert('排序成功');
			  },

		   });

	});
	 <!-- 排序结束-->


</script>

</section>
<!-- Main content END-->
{/block}
{block name="script"}
{/block}
